<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
%>
<!--  添加学科组 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
		<title>添加教研室</title>
		<base target="_self" />
	<link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
	<script language="javascript" src="<%=path %>/js/syAjax.js"></script>
	<script language="javascript" src="<%=path %>/js/jquery.js"></script>
	<script type="text/javascript">
		window.name="editStaffRoom";
		var objectHIDDENID="";
      function checkID()
      {
  		var organizationId=document.getElementById("organizationId").value;
  		if(/.*[\u4e00-\u9fa5]+.*$/.test(organizationId)) 
		{ 
			alert("编号不能含有汉字！"); 
			return false; 
		} 
        syAjax.request("post","<%=path %>/checkIDorganizationAction.action","organization.organizationId="+organizationId,{success:initSuccessResult,fail:onFail,type:'plain'});
      }
      
      function initSuccessResult(response)
      {
        if(response=="true")
		  {
		      //2010-10-12  添加设置教研组长
	         var paramArr="";
		     submitForm();
		  }else
		  {
		     alert("编号已存在！");
		  }
      }
	      
	function checkForm()
	{
	  var name=document.getElementById("orgname").value;
	  var organizationId=document.getElementById("organizationId").value;
	  var sort=document.getElementById("sort");
	  if(name=="")
	  {
	    alert("名称不能为空！");
	    return false;
	  }
	  if(organizationId=="")
	  {
	    alert("编号不能为空！");
	    return false;
	  }
	  if(!/^-?[\d]{0,9}$/.test(sort.value)){
	  	alert("序号格式不正确！");
	  	sort.focus();
	    return false;
	  }
	  checkID();
	}
	
	
  
  function giveParamArr(){
	  		return document.getElementById(objectHIDDENID).value;
	  }
	
	function choseUser(){
	  objectHIDDENID="UserIds";
	  parent.objectHIDDENID=objectHIDDENID;
	  if('${applicationScope.currentYear}'==null || '${applicationScope.currentYear}'==""){
		alert("未设置当前年度，请通知管理员进行设置！");
		return;
	   	}
       var url="<%=path%>/toSelectTeacherorganizationAction.action?years=${applicationScope.currentYear}&role.roleId=jyzz&actionURL=&t="+new Date();	
		
	   parent.displayModuleDiv2(url);
    }
	
	function doChooseUser(returnStr){
		
		var idStr="";
			if(returnStr==undefined){
				return;
			}
		if(returnStr!=null && returnStr!=""){
			var UserArr = returnStr.substring(0,returnStr.length-1).split(",");
			
			var UserNameStr="";
			for(var i=0;i<UserArr.length;i++){
				var user=UserArr[i];
				var sonArr=user.split("_");
				if((i+1)%5==0){
					UserNameStr+="&nbsp;&nbsp;"+sonArr[1]+"&nbsp;&nbsp;&nbsp;"+"<input name=\"UserId\" type=\"hidden\" value=\""+sonArr[0]+"\"/><br>";
				}else{
					UserNameStr+="&nbsp;&nbsp;"+sonArr[1]+"&nbsp;&nbsp;&nbsp;"+"<input name=\"UserId\" type=\"hidden\" value=\""+sonArr[0]+"\"/>";		
				}
				idStr+=sonArr[0]+",";
			}
			
			document.getElementById("UserIds").value=idStr;
			if(UserNameStr!=""){									
				document.getElementById("pName").innerHTML=UserNameStr;					
			}	
		}else{
			document.getElementById("pName").innerHTML="点击此处设置教研室负责人";
		}	
  }
  
  	//提交
	function submitForm() {
				var url = "<%=path %>/saveOrUpdateStaffRoomorganizationAction.action"
			$.post(url,
				$('#staffRoomForm').serialize(), 
				function(data){
					//window.returnValue = data;
					//window.close();	
					parent.refreshJsp();		
			})
	}
	</script>
  </head>
  
  <body bgcolor="#ECE9D8">
  <form id="staffRoomForm" target="editStaffRoom" action="" method="post" name="staffRoomForm">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25" align="left" valign="bottom" bgcolor="#ECE9D8" class="f_8"><table width="100%"><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;注：<span class="f_11">*</span>为必填项</td></tr></table></td>
  </tr>
  <tr>
    <td height="12" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="top" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="30" align="right" class="f_6"><span class="f_11">* </span>编号：</td>
        <td align="left"><input type="text" name="organization.organizationId" id="organizationId" maxlength="50"/></td>
      </tr>
      <tr>
        <td width="25%" height="30" align="right" class="f_6" nowrap="nowrap"><span class="f_11">* </span>教研室名称：</td>
        <td width="75%" align="left">
        	<input type="text" name="organization.name" id="orgname" maxlength="25"/>
        	<input type="hidden" name="organization.orgType" value="1" />
        </td>
      </tr>
      
	  <tr>
	     <td height="30" align="right" bgcolor="#ECE9D8" class="f_6" nowrap="nowrap">教研室负责人：</td>
	     <td align="left">
	     <input type="hidden" name="years" value="${applicationScope.currentYear}"/>
	     <input type="hidden" name="role.roleId" value="jyzz"/>
	     <div style="border:1px;border-style:dotted; background-color: #FFFFFF;width: 150px" onclick="choseUser();" class="border_3"onmouseover="this.style.backgroundColor='#e4f5ff'" onmouseout="this.style.backgroundColor=''" style="cursor:pointer;" id="pName">
	          点击此处设置教研室负责人
	     </div>
	     <input type="hidden"  value="" id="UserIds" name="UserIds" />
	     </td>
	   </tr>
  
      <tr>
        <td height="30" align="right" class="f_6">序号：</td>
        <td align="left"><input type="text" name="organization.sort" id="sort" value="0" /></td>
      </tr>
      <tr>
        <td height="30" align="right" valign="top" class="f_6" nowrap="nowrap">包含课程：</td>
        <td align="left" valign="top">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" valign="top" class="tb_10 border_2">
            <table width="350" border="0" cellspacing="0" cellpadding="0">
             
                <c:choose>
                  <c:when test="${! empty courseUserList}">
                    <c:set value="1" var="i" />
                    <c:forEach items="${courseUserList}" var="course">
                      <tr>
                      <td height="25" align="left">
                      	<input type="checkbox" name="courseId" value="${course.courseId }" />${course.name }
                      </td>	
                        </tr>
                      <c:set value="${i+1}" var="i" />
                    </c:forEach>
                  </c:when>
                  <c:otherwise><td><font color="#CCCCCC">无课程信息</font></td></c:otherwise>
                </c:choose>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="middle" bgcolor="#ECE9D8">
    <table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="middle" bgcolor="#ECE9D8"><input type="button" name="button" onclick="checkForm();" value="提 交" /></td>
  </tr>
</table>
</form>
  </body>
</html>
